# -*- coding: utf-8 -*-
from django.db import models
from django.contrib import admin
from django.contrib.auth.models import User
import django.utils.timezone as timezone
import sys
reload(sys)
sys.setdefaultencoding('utf8')
# Create your models here.
""" delete by houchaoqun 20161128
STATUS_CHOICES = (
    ('d', 'Draft'),
    ('p', 'Published'),
    ('w', 'Withdrawn'),
)

class Article(models.Model):
    title = models.CharField(max_length=100)
    body = models.TextField()
    status = models.CharField(max_length=1, choices=STATUS_CHOICES)

    def __str__(self):              # __unicode__ on Python 2
        return self.title
"""

## author：Hou chaoqun
## function：create app_TuringClass's tables
## date：2016/11/22

class QuestionTag(models.Model):
    TagID = models.CharField(primary_key = True, max_length = 10, verbose_name = u'问题标签ID')
    TagName = models.CharField(max_length = 20, verbose_name = u'标签名称')
    Note = models.CharField(default = 'None', max_length = 200, verbose_name = u'备注')

    def __unicode__(self):
        return self.TagID + '_' + self.TagName


class QuestionList(models.Model):
    QuestionID = models.IntegerField(primary_key = True, verbose_name = u'问题ID')
    QuestionAbstract = models.CharField(max_length = 200, verbose_name = u'问题摘要')
    # QuestionContent = models.CharField(max_length = 10000, verbose_name = u'问题内容')
    QuestionContent = models.TextField(verbose_name = u'问题内容')
    TagsID = models.CharField(max_length = 100, verbose_name = u'问题标签ID')
    BrowseNum = models.IntegerField(default = 0, verbose_name = u'浏览次数')
    AnswerNum = models.IntegerField(default = 0, verbose_name = u'回答次数')
    PraiseNum = models.IntegerField(default = 0, verbose_name = u'点赞次数')
    OpposeNum = models.IntegerField(default = 0, verbose_name = u'反对次数')
    QuizzerID = models.CharField(default = 'default', max_length = 20, verbose_name = u'提问者ID')
    QuizzerName = models.CharField(default = 'default', max_length = 20, verbose_name = u'提问者昵称')
    LastModifyDate = models.DateTimeField(verbose_name = u'最后修改日期')
    QuestionCreateDate = models.DateTimeField(auto_now_add = True, verbose_name = u'提问日期')
    SupportByUserID = models.CharField(max_length = 5000, verbose_name = u'点赞用户ID串', null = True)          # 该问题被哪些用户点赞了
    NonSupportByUserID = models.CharField(max_length = 5000, verbose_name = u'不支持的用户ID串', null = True)   # 该问题被哪些用户踩了
    FocusByUserID = models.CharField(max_length = 5000, verbose_name = u'关注的标签ID串', null = True)          # 针对students,该问题被哪些用户收藏（关注）了
    AcceptedAnswerID = models.CharField(max_length = 400, verbose_name = u'采纳答案ID', null = True)
    Note = models.CharField(default = 'None', max_length = 100, verbose_name = u'备注')

    def __unicode__(self):
        return str(self.QuestionID) + '_' + self.QuestionAbstract + '_' + self.QuizzerID + '_' + self.QuizzerName

## QuestionDetails表：
## 用户提交的问题先存入该表，默认状态“未审核”，等待管理员审核通过
## 审核通过后，存入QuestionList表，并显示在主页
QUESTION_STATUS = (
    ('Pending', '待审核'),
    ('Approved', '审核通过'),
    ('UnApproved', '未审核通过'),
)

class QuestionDetails(models.Model):
    QuestionID = models.IntegerField(primary_key = True, verbose_name = u'问题ID')
    QuestionAbstract = models.CharField(max_length = 200, verbose_name = u'问题摘要')
    # QuestionContent = models.CharField(max_length = 10000, verbose_name = u'问题内容')
    QuestionContent = models.TextField(verbose_name = u'问题内容')
    QuizzerID = models.CharField(default = 'default', max_length = 20, verbose_name = '提问者ID')
    TagsID = models.CharField(default = 'default', max_length = 100, verbose_name = u'问题标签ID')
    QuestionStatus = models.CharField(default = 'Approved', max_length = 10, choices = QUESTION_STATUS)
    CheckerID = models.CharField(default = 'default', max_length = 20, verbose_name = '审核者ID')
    QuestionCheckDate = models.DateTimeField(default = timezone.now, auto_now_add = True, verbose_name = u'审核日期')
    Note = models.CharField(default = 'None', max_length = 100, verbose_name = u'备注')

    def __unicode__(self):
        return str(self.QuestionID) + '_' + self.QuestionAbstract + '_' + self.CheckerID + '_' + self.QuestionStatus

## 回答表 QuestionAnswers()
## 一个问题对应多个答案
## 一个答案对应一个问题
class QuestionAnswers(models.Model):
    AnswerID = models.CharField(primary_key = True, max_length = 250, verbose_name = u'答案ID')
    QuestionID = models.IntegerField(verbose_name = u'问题ID')
    # AnswerContent = models.CharField(max_length = 20000, verbose_name = u'回答内容')
    AnswerContent = models.TextField(verbose_name = u'问题内容')
    ResponderID = models.CharField(max_length = 20, verbose_name = u'回答者ID')
    ResponderName = models.CharField(max_length = 20, verbose_name = u'回答者姓名')
    PraiseNum = models.IntegerField(default = 0, verbose_name = u'点赞次数')
    OpposeNum = models.IntegerField(default = 0, verbose_name = u'反对次数')
    SupportByUserID = models.CharField(max_length = 5000, verbose_name = u'点赞用户ID串', null = True)
    NonSupportByUserID = models.CharField(max_length = 5000, verbose_name = u'不支持的用户ID串', null = True)
    AnswerDate = models.DateTimeField(default = timezone.now, auto_now_add = True, verbose_name = u'答题日期')
    IsAccepted = models.IntegerField(default = 0, verbose_name = u'是否采纳')
    Note = models.CharField(default = 'None', max_length = 100, verbose_name = u'备注')

    def __unicode__(self):
        return str(self.QuestionID) + '_' + self.ResponderName

## author：Deng shi yan
## checker: Hou chaoqun
## function：UploadingFiles
## date：2016/11/25
class UploadingFiles(models.Model):
    FileName = models.CharField(max_length = 300, verbose_name = u'文件名')
    UploaderID = models.CharField(max_length = 20, verbose_name = u'上传者ID')
    UploaderName = models.CharField(max_length = 20, verbose_name = u'上传者姓名')
    DownloadNum = models.IntegerField(default = 0, verbose_name = u'下载次数')
    UploadingDate = models.DateTimeField(default = timezone.now, auto_now_add = True, verbose_name = u'上传日期')
    Note = models.CharField(default = 'None', max_length = 100, verbose_name = u'备注')

    def __unicode__(self):
        return self.FileName + '_' + self.UploaderName

## 预约模块预约表
class Appointment(models.Model):
    AppointmentID = models.CharField(max_length = 100, primary_key = True, verbose_name = u'ID')
    StudentNum = models.CharField(max_length = 15, verbose_name = u'学号')
    Name = models.CharField(max_length = 20, verbose_name = u'姓名')
    UserID = models.CharField(max_length = 20, verbose_name = u'用户ID')
    School = models.CharField(max_length = 50, verbose_name = u'学院')
    Detail = models.CharField(max_length = 200, verbose_name = u'维修内容', null = True)
    MobilePhone = models.CharField(max_length = 15, verbose_name = u'手机号码', null = True)
    UserQQ = models.CharField(max_length = 15, verbose_name = u'QQ', null=True)
    SequenceNumber = models.IntegerField(verbose_name = u'名次')
    CreateDate = models.DateTimeField(auto_now_add = True, verbose_name = u'创建日期')
    AppointmentDate = models.CharField(max_length = 40, verbose_name = u'预约时间')
    DateID = models.CharField(max_length = 20, verbose_name = u'时段id')
    Done = models.IntegerField(default = 0, verbose_name = u'是否完成维修')
    InQueue = models.IntegerField(default = 1, verbose_name = u'是否在队列中')
    Comment = models.CharField(max_length = 500, null = True, verbose_name = u'评价')
    Point = models.IntegerField(null = True, verbose_name = u'评分')
    StaffID = models.CharField(max_length = 20, verbose_name = u'维修人员')

    def __unicode__(self):
        return self.StudentNum + '_' + self.School

## 预约模块时间
class AvailableDate(models.Model):
    DateID = models.CharField(primary_key = True, max_length = 40, verbose_name = u'时段id')
    activityAbstract = models.CharField(max_length = 400, verbose_name = u'活动简介', null = True)
    StartTime = models.CharField(max_length = 50, verbose_name = u'开始时间')
    EndTime = models.CharField(max_length = 50, verbose_name = u'结束时间')
    Number = models.IntegerField(default = 0, verbose_name = u'人数')
    Limit = models.IntegerField(verbose_name = u'人数限制')
    IsFinished = models.IntegerField(default = 0, verbose_name = u'活动是否完成')
    Showing = models.IntegerField(default = 0, verbose_name = u'是否显示')

    def __unicode__(self):
        return self.DateID + '_' + self.StartTime

## 预约模块维修人员
class Staff(models.Model):
    StaffID = models.CharField(primary_key = True, max_length = 20, verbose_name = u'维修人员')
    Name = models.CharField(max_length = 20, verbose_name = u'姓名')
    MobilePhone = models.CharField(max_length = 11, verbose_name = u'手机号码')
    UserQQ = models.CharField(max_length = 15, verbose_name = u'QQ', null = True)
    Duty = models.CharField(max_length = 300, verbose_name = u'工作时间', null = True)
    Point = models.IntegerField(verbose_name = u'评分', null = True)

    def __unicode__(self):
        return self.StaffID + '_' + self.Name

## 回复
class Reply(models.Model):
    ReplyID = models.CharField(primary_key = True, max_length = 80, verbose_name = u'回复ID')
    AnswerID = models.CharField(max_length = 400, verbose_name = u'答案ID')
    UserID = models.CharField(max_length = 20, verbose_name = u'回复者的用户ID')
    To = models.CharField(max_length = 20, verbose_name = u'被回复的用户ID')
    content = models.CharField(max_length = 10000, verbose_name = u'内容')
    ReplyDate = models.DateTimeField(default = timezone.now, auto_now_add = True, verbose_name = u'回复日期')

    def __unicode__(self):
        return self.ReplyID + '_' + self.AnswerID

## 新闻公告
class Notification(models.Model):
    NotificationID = models.CharField(primary_key = True, max_length = 40, verbose_name = u'新闻ID')
    Title = models.CharField(max_length = 100, verbose_name = u'标题')
    UserID = models.CharField(max_length = 20, verbose_name = u'发布用户ID')
    Content = models.TextField(verbose_name = u'内容')
    CreateDate = models.DateTimeField(default = timezone.now, auto_now_add = True, verbose_name = u'发布日期')
    Priority = models.IntegerField(default = 0, verbose_name = u'优先级')
    TypeName = models.CharField(max_length = 20, verbose_name = u'类型名称') # News, Announcement

    def __unicode__(self):
        return self.Title


## 活动积分
class ActivityScore(models.Model):
    ID = models.CharField(primary_key = True, max_length = 60, verbose_name = u'ID')
    UserID = models.CharField(max_length = 20, verbose_name = u'用户ID')
    DateID = models.CharField(max_length = 20, verbose_name = u'活动ID')
    Score = models.IntegerField(default = 0, verbose_name = u'积分')

    def  __unicode__(self):
        return self.ID
